import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class PowerUp extends Rectangle2D.Double{

    float x, y;
    float xVelocity, yVelocity;
    private String imageURL;
    private String targetClassName;
    private String type;

    // Constructor
    public PowerUp(int x, int y, String type) {

        // Location & velocity
        width = 42;
        height = 42;
        this.x = x;
        this.y = y;
        this.xVelocity = 0;
        this.yVelocity = 2;
        setFrame(x-width/2, y-height/2, width, height);

        // Set type of powerup
        this.type = type;

        // PowerUp Image Handler
        switch(type) {
            case "Longer Paddle":
                targetClassName = Paddle.class.getName();
                imageURL = "";
                break;
            case "Shorter Paddle":
                targetClassName = Paddle.class.getName();
                imageURL = "";
                break;
            case "Faster Paddle":
                targetClassName = Paddle.class.getName();
                imageURL = "";
                break;
            case "Slower Paddle":
                targetClassName = Paddle.class.getName();
                imageURL = "";
                break;
            case "Faster Ball":
                targetClassName = Ball.class.getName();
                imageURL = "";
                break;
            case "Slower Ball":
                targetClassName = Ball.class.getName();
                imageURL = "";
                break;
            case "Triple Ball":
                targetClassName = Ball.class.getName();
                imageURL = "";
                break;

            default:
                imageURL = "";
                break;
        }
        imageURL = "resources/star.png";

    }

    public String getType() {
        return type;
    }

    public String getTargetClassName() {
        return targetClassName;
    }


    public BufferedImage getImage() {
        BufferedImage img = null;
        try {

            img = ImageIO.read(new File(imageURL));
        }
        catch (IOException e) {
            System.out.println("Can't find img");
            e.printStackTrace();
        }
        return img;
    }

    public void update(double delta) {
        setFrame(x-width/2, y-height/2, width, height);
        //lastX = x;
        //lastY = y;

        x += xVelocity * delta;
        y += yVelocity * delta;
    }

}
